package com.kvc.extend.papervision3d {
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.materials.special.LineMaterial;		

	/**
	 * @author Kevin Cao
	 */
	public class PlaneGrid3D extends Lines3D {

		public function PlaneGrid3D(gridX : Number = 11, gridZ : Number = 11, dist : Number = 80, material : LineMaterial = null, name : String = null) {
			
			var i : int = 0;
			
			var v1 : Vertex3D;
			var v2 : Vertex3D;
			var l : Line3D;
			var lm : LineMaterial = material ? material : new LineMaterial(0x999999, .5);
			
			super(lm, name);
			
			for (i = 0;i < gridX; i++) {
				v1 = new Vertex3D(i * dist, 0, 0);
				v2 = new Vertex3D(i * dist, 0, (gridZ-1) * dist);
				l = new Line3D(this, lm, 1, v1, v2);
				addLine(l);
			}
			
			for (i = 0;i < gridZ; i++) {
				v1 = new Vertex3D(0, 0, i * dist);
				v2 = new Vertex3D((gridX-1) * dist, 0, i * dist);
				l = new Line3D(this, lm, 1, v1, v2);
				addLine(l);
			}
			
			x = -dist * (gridX - 1) / 2;
			z = -dist * (gridZ - 1) / 2;
		}
	}
}
